package com.jsoft.jsofted.platform.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.diboot.core.binding.annotation.BindField;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsNotNull;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import com.jsoft.jsofted.framework.entity.TimeEntity;
import com.jsoft.jsofted.framework.entity.TreeEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Id;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.LinkedList;

/**
 * 功能菜单表
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Table("sys_menu")
@TableName("sys_menu")
public class MenuEntity implements TimeEntity, TreeEntity {

    @Id
    @Column
    @TableId(type = IdType.ASSIGN_ID)
    protected Long id;

    @Column
    protected Long parentId;

    @TableField(exist = false)
    @BindField(entity = MenuEntity.class, field = "name", condition = "parent_id=id")
    protected String parentName;

    @TableField(exist = false)
    @BindField(entity = MenuEntity.class, field = "full_name", condition = "parent_id=id")
    protected String parentFullName;

    @Column(length = 64)
    @IsNotNull
    protected String name;

    @Column(length = 256)
    protected String fullName;

    /**
     * 菜单定义了些什么操作？授权的时候会用到。
     * [{code: '', name: ''}, ... ]
     */
    @TableField(typeHandler = FastjsonTypeHandler.class)
    @Column(type = MySqlTypeConstant.VARCHAR, length = 2000)
    protected LinkedList actions;

    /**
     * 菜单路径：点击菜单时浏览器地址栏显示地址后半部分（相对路径部分）
     */
    @Column(length = 64)
    protected String path;

    /**
     * 菜单页面：点击菜单时加载的页面代码。
     */
    @Column(length = 64)
    protected String page;

    @Column(length = 32)
    protected String icon;

    @Column(length = 20, decimalLength = 6)
    @IsNotNull
    protected BigDecimal sortValue;

    @Column
    @IsNotNull
    protected Timestamp createTime;

    @Column
    @IsNotNull
    protected Timestamp updateTime = new Timestamp(System.currentTimeMillis());

}
